package com.day11.homework;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Properties;

public class PropertyInvocationHandler implements InvocationHandler {
    private Properties properties;

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    public PropertyInvocationHandler(Properties properties) {
        this.properties = properties;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String property;
        PropertyValueRead propertyValueRead = method.getAnnotation(PropertyValueRead.class);
        if (propertyValueRead == null) {
            property = null;
        } else {
            property = properties.getProperty(propertyValueRead.value());
        }
        return property;
    }
}
